package com.example.blog.service.impl;

import com.example.blog.dao.FriendMapper;
import com.example.blog.pojo.FriendLink;
import com.example.blog.service.FriendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @date: 2020/9/13
 * @author: 东北宋小宝
 * @version: 1.0
 * @Description:
 */
@Service
public class FriendServiceImpl implements FriendService {
    @Resource
    private FriendMapper friendMapper;
    /***
     * 获取一个友链
     * @param id
     * @return
     */
    @Override
    public FriendLink getFriendLink(Long id) {
        return friendMapper.getFriendLink(id);
    }

    /***
     * 获取一堆友链
     * @return
     */
    @Override
    public List<FriendLink> getAllFriendLink() {
        return friendMapper.getAllFriendLink();
    }

    /***
     * 保存 and 编辑 一个友链
     * @param friendLink
     */
    @Override
    public void saveFriendLink(FriendLink friendLink) {
        if (friendLink.getId() != null) {
            friendMapper.updateFriendLink(friendLink);
        } else {
            friendLink.setCreateTime(new Date());
            friendMapper.insertFriendLink(friendLink);
        }
    }

    /***
     * 删除一个友链
     * @param id
     */
    @Override
    public void deleteFriendLink(Long id) {
        friendMapper.deleteFriendLink(id);
    }
}
